package com.example.test;
import java.util.*;
public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int m = scanner.nextInt();
        int k = scanner.nextInt();
        List<Integer> pusher = new LinkedList<>();//推送器
        List<Integer> box = new LinkedList<>(); //盒子
        List<Integer> good = new LinkedList<>();
        for (int i = 0; i < n; i++) {
            int a = scanner.nextInt();
            pusher.add(a);
        }
        while (!pusher.isEmpty() || !box.isEmpty()) {
            if (good.isEmpty()) {
                if (box.isEmpty()) {
                    good.add(pusher.get(0));
                    pusher.remove(0);
                } else {
                    good.add(box.get(box.size() - 1));
                    box.remove(box.size() - 1);
                }
            } else { //旧枝干
                if (!box.isEmpty() && box.get(box.size() - 1) <= good.get(good.size() - 1)) {
                    good.add(box.get(box.size() - 1));
                    box.remove(box.size() - 1);
                } else if (!pusher.isEmpty() && pusher.get(0) <= good.get(good.size() - 1)) {
                    good.add(pusher.get(0));
                    pusher.remove(0);
                } else if (!pusher.isEmpty() && pusher.get(0) > good.get(good.size() - 1)) {
                    box.add(pusher.get(0));
                    pusher.remove(0);
                } else {
                    print(good, true);
                    good = new LinkedList<>();
                }
            }
            if (good.size() >= k ||
                    (box.size() >= m && pusher.get(0) > good.get(good.size()-1)) ||
                    (pusher.isEmpty() && !box.isEmpty() && box.get(box.size() - 1) > good.get(good.size() - 1))) {
                print(good, true);
                good = new LinkedList<>();
            }
        }
        print(good,false);
    }
    public static void print(List<Integer> good, boolean k) {
        for (int i = 0; i < good.size(); i++) {
            System.out.print(good.get(i));
            if (i < good.size() - 1) {
                System.out.print(" ");
            }
        }
        if(k) System.out.println();
    }
}